package com.qqhf.common.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WebConfig {
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                // 解决tomcat不支持前端请求参数中有特殊字符的问题
                connector.setProperty("relaxedQueryChars", "|{}[]");
            }
        });
        return factory;
    }

    //@Override
    //protected void configure(HttpSecurity http) throws Exception {
    //    http.formLogin() // 自定义自己编写的登录页面
    //            .loginPage("/login.html") // 登录页面设置
    //            .loginProcessingUrl("/user/login") // 登录访问路径
    //            .defaultSuccessUrl("/test/index").permitAll() // 登录成功后的跳转路径
    //            .and().authorizeRequests()
    //            .antMatchers("/","/test/hello","/login.html").permitAll() // 设置哪些路径可以直接访问，不需要认证
    //            .anyRequest().authenticated()
    //            .and().csrf().disable(); // 关闭csrf防护
    //}
}
